//
//  RBGroupFilterPopVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/9/7.
//

#import "RBGroupFilterPopVC.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "RBPager.h"
#import <UIView+YYAdd.h>
#import "UIScrollView+RBAdd.h"

@interface RBGroupFilterPopVC ()

@property(nonatomic, strong)UIView *bottomView;

@end

@implementation RBGroupFilterPopVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.dismissOnTapBlank = NO;
    self.view.backgroundColor = UIColor.clearColor;
    
    UIView *coverView = UIView.new;
    coverView.clipsToBounds = YES;
    [coverView rbAddTapGesWithTarget:self action:@selector(dismiss)];
    coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [self.view addSubview:coverView];
    [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topInWindow);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    self.contentView = UIView.new;
    [self.contentView rbAddTapGesWithTarget:self action:@selector(eventPlaceholder)];
    [coverView addSubview:self.contentView];
    self.contentView.backgroundColor = UIColor.whiteColor;
    [self.contentView rbSetCorner:UIRectCornerBottomLeft | UIRectCornerBottomRight radius:Zoom(15)];
    
    CGFloat maxH = kRBMainScreenHeight - self.topInWindow - kRBSafeBottomHeight - Zoom(100);
    
    NSInteger itemCount = 19;
    CGFloat itemH = Zoom(35);
    CGFloat padding = Zoom(15);
    CGFloat itemW = (kRBMainScreenWidth - padding*2 - Zoom(30))/2;
    
    CGFloat totalH = Zoom(10);
    totalH += ceil(itemCount/2.0)*itemH;
    
    [self.contentView view_addView:({
        UIScrollView *view = UIScrollView.new;
        view.showsVerticalScrollIndicator = NO;
        view.showsHorizontalScrollIndicator = NO;
        [view rbSetContentWidth:kRBMainScreenWidth - padding*2];
        
        for (NSInteger i = 0; i < itemCount; i++)
        {
            UILabel *itemView = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:@"康普沃（CONGPUVOU)"];
            if(i%2)
            {
                [view addView:itemView withHeight:itemH width:itemW top:-itemH bottom:CGFLOAT_MIN left:CGFLOAT_MIN right:0 centerX:0];
            }
            else
            {
                [view addView:itemView withHeight:itemH width:itemW top:0 bottom:CGFLOAT_MIN left:0 right:CGFLOAT_MIN centerX:NO];
            }
        }
        
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:padding right:padding centerX:0];
    
    totalH += Zoom(20);
    totalH += Zoom(34);
    totalH += Zoom(13);
    
    [self.contentView view_addView:({
        UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:UIColor.whiteColor align:1 text:@"确定" bgColor:@"#F25B50" radius:Zoom(17)];
        [view rbAddTapGesWithTarget:self action:@selector(confirmBtnTapped)];
        view;
    }) withHeight:Zoom(34) width:CGFLOAT_MIN top:Zoom(20) bottom:Zoom(13) left:padding right:padding centerX:0];
    
    totalH = MIN(totalH, maxH);
    self.contentView.width = kRBMainScreenWidth;
    self.contentView.height = totalH;
    self.contentView.left = 0;
    self.contentView.bottom = 0;
}

- (void)show
{
    [UIView animateWithDuration:0.15 animations:^{
        self.contentView.top = 0;
    }];
}

- (void)dismiss
{
    [UIView animateWithDuration:0.15 animations:^{
        self.contentView.bottom = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}

#pragma mark - Network

#pragma mark - Event

- (void)eventPlaceholder
{
    
}

- (void)confirmBtnTapped
{
    [self dismiss];
}

#pragma mark - Setter

#pragma mark - Getter

@end
